package com.kuang.lesson02.upload

import java.io.File
import java.net.ServerSocket

/**
 * 文件上传服务端
 */
fun main() {
    ServerSocket(9999).use { server ->
        server.accept().use { socket ->
            socket.getInputStream().use { ips ->
                File("receive.txt").outputStream().use { ops ->
                    ips.copyTo(ops)

                    //通知客户端接收完毕
                    socket.getOutputStream().use {
                        it.write("接收完毕".toByteArray())
                    }
                }
            }
        }
    }
}